﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Text.RegularExpressions;

namespace University.Workshop.Business
{
    public static class ClientController
    {
        public static bool RegisterClient(string clientNit,string clientName,string clientSurname1,string clientSurname2,string clientPhone, string clientCellPhone, string clientEmail, string clientAddress)
        {
            if (string.IsNullOrEmpty(clientNit) || string.IsNullOrEmpty(clientName) || string.IsNullOrEmpty(clientSurname1) || string.IsNullOrEmpty(clientSurname2))
            {
                return false;
            }
            else
            {
                if (IsValidEmailAddress(clientEmail))
                {
                    if (ReviewIdIfNitRegister(clientNit))
                    {
                        Client client = new Client()
                        {
                            Nit = clientNit,
                            Name = clientName,
                            FatherLastName = clientSurname1,
                            MotherLastName = clientSurname2,
                            Phone = clientPhone,
                            CellPhone = clientCellPhone,
                            Email = clientEmail,
                            Address = clientAddress,
                            State = "A"
                        };
                        return ClientDataAccess.RegisterClient(client);
                    }
                    else
                        return false;
                }
                else
                    return false;
            }
        }

        public static bool IsValidEmailAddress(string sEmail)
        {
            if (string.IsNullOrEmpty(sEmail))
            {
                return true;
            }
            else
            {
                return Regex.IsMatch(sEmail, @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.(com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|[a-zA-Z]{3})$", RegexOptions.IgnorePatternWhitespace);
            }
        }

        public static bool ReviewIdIfNitRegister(string nit)
        {
            return ClientDataAccess.ReviewIdIfNitRegister(nit);
        }

        public static bool DeleteClient(string value)
        {
            return ClientDataAccess.DeleteClientData(value);
        }

        public static bool ModifyNameClient(string name, string nit)
        {
            if (string.IsNullOrEmpty(name))
                return false;
            else
                return ClientDataAccess.ModifyNameClient(name, nit);
        }

        public static bool ModifyPatNameClient(string pat, string nit)
        {
            if (string.IsNullOrEmpty(pat))
                return false;
            else
                return ClientDataAccess.ModifyPatClient(pat,nit);
        }

        public static bool ModifyMatNameClient(string mat, string nit)
        {
            return ClientDataAccess.ModifyMatClient(mat,nit);
        }

        public static bool ModifyPhoneClient(string phone, string nit)
        {
            return ClientDataAccess.ModifyPhoneClient(phone,nit);
        }

        public static bool ModifyCellClient(string cell, string nit)
        {
            return ClientDataAccess.ModifyCellClient(cell,nit);
        }

        public static bool ModifyEmailClient(string email, string nit)
        {
            return ClientDataAccess.ModifyEmailClient(email, nit);
        }

        public static bool ModifyAddressClient(string address, string nit)
        {
            return ClientDataAccess.ModifyAddressClient(address, nit);
        }


    }
}

